﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Routing;
using TiTi.tea.Api.Attributes;
using TiTi.tea.Api.Models;
using TiTi.tea.BLL;
using TiTi.tea.Comm;
using TiTi.tea.Dto;

namespace TiTi.tea.Api.Controllers
{
    [RoutePrefix("api/coupon")]
    public class CouponController : ApiController
    {
        private UserCouponBLL bll = new UserCouponBLL();

        /// <summary>
        /// 获取用户已有优惠卷
        /// </summary>
        /// <returns></returns>
        [Route("getByUser")]
        [HttpGet]
        [MyAuthorize]
        public Result GetByUser()
        {
            IHttpRouteData routeData = Request.GetRouteData();
            IDictionary<string, object> dict = routeData.Values;
            var auth = dict["auth"] as AuthInfo;
            var userId = auth.UserId;

            var data = bll.GetByUser(userId).Select(o => new CouponDto()
            {
                id = o.Id,
                money = o.Money,
                reduce = o.Discounts,
                status = o.Status ?? 0,
                CreateTime = o.CreateTime,
                EndTime = o.EndTime,
            });
            return Result.Success(data);
        }
    }
}